<template>
  <el-card class="box-card" v-loading="loading">
    <template #header>
      <div class="card-header">
        <span>系统更新</span>
      </div>
    </template>
    <div style="display: flex; justify-content: space-between">
      <div style="display: flex; flex-direction: row; width: 600px">
        <el-input
          v-model="reqData.search"
          style="max-width: 323px"
          placeholder="关键词"
          class="height40"
          clearable
        >
          <template #append>
            <el-button type="primary" @click="fetchNewsList">搜索</el-button>
          </template>
        </el-input>

        <el-radio-group
          size="large"
          v-model="reqData.type"
          style="display: flex; flex-direction: row; margin-left: 40px"
          @change="fetchNewsList"
        >
          <el-radio-button label="1" :value="1">数据更新</el-radio-button>
          <el-radio-button label="2" :value="2">版本更新</el-radio-button>
        </el-radio-group>
      </div>

      <el-button type="primary" class="height40" @click="handleAddNew"
        >新增</el-button
      >
    </div>
    <el-table
      :data="newList"
      style="width: 100%"
      class="margintop"
      stripe
      :header-cell-style="{ 'border-bottom': 'none' }"
      :header-row-style="{ height: '60px' }"
      :cell-style="{ height: '60px', 'border-bottom': 'none' }"
    >
      <el-table-column prop="name" label="标题" />
      <el-table-column prop="create_time" label="创建时间" width="200" />
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-tooltip
            class="box-item"
            effect="dark"
            content="编辑"
            placement="top"
          >
            <el-icon
              size="20"
              style="cursor: pointer"
              @click="editChange(scope.row)"
              ><EditPen
            /></el-icon>
          </el-tooltip>
          <!-- <el-tooltip
            class="box-item"
            effect="dark"
            content="删除"
            placement="top"
          >
            <el-icon
              @click="handleDelete(scope.row)"
              size="20"
              style="cursor: pointer; margin-left: 10px"
              ><Delete
            /></el-icon>
          </el-tooltip> -->
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      v-model:page="reqData.page"
      v-model:limit="reqData.pageSize"
      :total="total"
      :background="false"
      @pagination="fetchNewsList"
    ></pagination>
  </el-card>
</template>
<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import Pagination from '@/components/Pagination/index.vue';
import operation from '@/modules';
const { systermUpdateList } = operation;
// const { proxy } = getCurrentInstance();

const loading = ref(false);
const router = useRouter();
const total = ref(0);
const reqData = ref({
  pageSize: 10,
  page: 1,
  type: 1,
  search: '',
});
const newList = ref([]);

function editChange(row) {
  router.push({
    path: '/operation/addSystemUpdata',
    query: { id: row.id, type: reqData.value.type },
  });
}

const fetchNewsList = () => {
  loading.value = true;
  systermUpdateList(reqData.value)
    .then((res) => {
      if (res.code == 20000) {
        total.value = res.data.total;
        newList.value = res.data.data;
        loading.value = false;
      } else {
        loading.value = false;
      }
    })
    .catch(() => {
      loading.value = false;
    });
};
fetchNewsList();
const handleAddNew = () => {
  router.push({
    path: './addSystemUpdata',
    query: { type: reqData.value.type },
  });
};
</script>
<style lang="scss" scoped>
:deep(.el-input-group__append) {
  margin-top: -1px;
  height: 42px;
}
::v-deep(.el-form--inline .el-form-item) {
  margin-right: 7px;
}

::v-deep(.el-form-item--default) {
  margin-bottom: 4px;
}
.box-card {
  margin: 20px;

  .card-header {
    font-size: 20px;
    font-weight: 600;
    color: #1d2129;
    padding: 10px;
    .headerSize {
      color: #4e5969;
      font-size: 14px;
      margin-left: 12px;
      font-weight: 400;
      height: 20px;
      line-height: 21px;
    }
  }
}
</style>
